<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import="java.util.*"%>
<%@ page import="java.text.*"%>
<html>
<head>
    <title>管理员查询</title>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://cdn.staticfile.org/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
    <link rel="stylesheet" href="${pageContext.request.contextPath }/css/layui.css" />
    <link href="${pageContext.request.contextPath }/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/css/common.css" />
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/css/slide.css" />
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/css/bootstrap.min.css" />
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/css/flat-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/css/jquery.nouislider.css">
    <script src="${pageContext.request.contextPath }/js/jquery.min.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath }/js/layui.js" media="all" ></script>
    <script src="${pageContext.request.contextPath }/js/bootstrap.min.js"></script>
    <script src="${pageContext.request.contextPath }/js/layui.js" charset="utf-8"></script>
    <script type="text/javascript">
        $(function(){
            $.ajax({
                type:"get",
                url:"${pageContext.request.contextPath }/admin/goUserLimit",
                data:{
                    pageNum:1
                },
                dataType:"json",
                success:function(data){
                    console.log(data);
                    var tr="";
                    $.each(data.list, function(index,info) {
                        tr+="<tr><th>"+info.userId+"</th><th>"+info.usersName+"</th>"+
                            "<th>"+info.password+"</th>"+
                            "<th><img src='../img/"+info.protrait+"'/></th>"+"<th>"+info.phone+"</th>"+
                            "<th>"+info.usersEmail+"</th>"+ "<th>"+info.likeType+"</th>"+
                            "<th><button id='updateUser' class='btn btn-success btn-xs' data-toggle='modal' data-target='#updates' value='"+info.userId+"'>修改</button>"+
                            "<button class='btn btn-danger btn-xs ' data-toggle='modal' value='"+info.userId+" 'id='delUsers'>删除</button></th></tr>";
                    });
                    $("#table-list").append(tr);
                    $("#prev").val(data.hasPreviousPage);
                    $("#next").val(data.hasNextPage);
                    $("#nowPage").val(data.pageNum);

                }
            });

            $("#p-button").on("click", "#bt", function(){
                $.ajax({
                    type:"get",
                    url:"${pageContext.request.contextPath }/admin/goUserLimit",
                    data:{
                        pageNum:$(this).val()
                    },
                    contentType:"application/json;charset=utf-8",//可有可无
                    dataType:"json",
                    success:function(data){
                        $("#prev").val(data.hasPreviousPage);
                        $("#next").val(data.hasNextPage);
                        $("#nowPage").val(data.pageNum);
                        var tr="";
                        $.each(data.list, function(index,info) {
                            tr+="<tr><th>"+info.userId+"</th><th>"+info.usersName+"</th>"+
                                "<th>"+info.password+"</th>"+
                                "<th><img src='../img/"+info.protrait+"'/></th>"+"<th>"+info.phone+"</th>"+
                                "<th>"+info.usersEmail+"</th>"+ "<th>"+info.likeType+"</th>"+
                                "<th><button id='updateUser' class='btn btn-success btn-xs' data-toggle='modal' data-target='#updates' value='"+info.userId+"'>修改</button>"+
                                "<button class='btn btn-danger btn-xs ' data-toggle='modal' value='"+info.userId+" 'id='delUsers'>删除</button></th></tr>";
                        });
                        $("#table-list").html(tr);
                    }
                });
            });

            //上一页
            $("#prev").click(function () {
                var pageNum = 0;
                if ($(this).val()=="false"){
                    pageNum = $("#nowPage").val();
                }else if($(this).val()=="true"){
                    pageNum =  $("#nowPage").val()-1;
                }
                $.ajax({
                    type:"get",
                    url:"${pageContext.request.contextPath }/admin/goUserLimit",
                    data:{
                        pageNum:pageNum
                    },
                    contentType:"application/json;charset=utf-8",//可有可无
                    dataType:"json",
                    success:function(data){
                        var tr="";
                        $.each(data.list, function(index,info) {
                            tr+="<tr><th>"+info.userId+"</th><th>"+info.usersName+"</th>"+
                                "<th>"+info.password+"</th>"+
                                "<th><img src='../img/"+info.protrait+"'/></th>"+"<th>"+info.phone+"</th>"+
                                "<th>"+info.usersEmail+"</th>"+ "<th>"+info.likeType+"</th>"+
                                "<th><button id='updateUser' class='btn btn-success btn-xs' data-toggle='modal' data-target='#updates' value='"+info.userId+"'>修改</button>"+
                                "<button class='btn btn-danger btn-xs ' data-toggle='modal' value='"+info.userId+" 'id='delUsers'>删除</button></th></tr>";
                        });
                        $("#table-list").html(tr);
                        $("#prev").val(data.hasPreviousPage);
                        $("#next").val(data.hasNextPage);
                        $("#nowPage").val(data.pageNum);
                    }
                });
            })


            // 下一页
            $("#next").click(function () {
                console.log($(this).val())
                var pageNum = 0;
                if ($(this).val()=="false"){
                    pageNum = $("#nowPage").val();
                }else if($(this).val()=="true"){
                    pageNum = parseInt($("#nowPage").val())+1;
                    console.log(pageNum)
                }
                $.ajax({
                    type:"get",
                    url:"${pageContext.request.contextPath }/admin/goUserLimit",
                    data:{
                        pageNum:pageNum
                    },
                    contentType:"application/json;charset=utf-8",//可有可无
                    dataType:"json",
                    success:function(data){
                        var tr="";
                        $.each(data.list, function(index,info) {
                            tr+="<tr><th>"+info.userId+"</th><th>"+info.usersName+"</th>"+
                                "<th>"+info.password+"</th>"+
                                "<th><img src='../img/"+info.protrait+"'/></th>"+"<th>"+info.phone+"</th>"+
                                "<th>"+info.usersEmail+"</th>"+ "<th>"+info.likeType+"</th>"+
                                "<th><button id='updateUser' class='btn btn-success btn-xs' data-toggle='modal' data-target='#updates' value='"+info.userId+"'>修改</button>"+
                                "<button class='btn btn-danger btn-xs ' data-toggle='modal' value='"+info.userId+" 'id='delUsers'>删除</button></th></tr>";
                        });
                        $("#table-list").html(tr);
                        $("#prev").val(data.hasPreviousPage);
                        $("#next").val(data.hasNextPage);
                        $("#nowPage").val(data.pageNum);
                    }
                });
            })

            // 关键字搜索
            $("#search").click(function () {
                $.ajax({
                    type: "get",
                    url: "${pageContext.request.contextPath}/admin/adminByUser",
                    dataType: "json",
                    data: {
                        keyword: $("#keyword").val()
                    },
                    success: function (data) {
                        if (data != "") {
                            var tr = "";
                            $.each(data, function (index, info) {
                                tr+="<tr><th>"+info.userId+"</th><th>"+info.usersName+"</th>"+
                                    "<th>"+info.password+"</th>"+
                                    "<th><img src='../img/"+info.protrait+"'/></th>"+"<th>"+info.phone+"</th>"+
                                    "<th>"+info.usersEmail+"</th>"+ "<th>"+info.likeType+"</th>"+
                                    "<th><button id='updateUser' class='btn btn-success btn-xs' data-toggle='modal' data-target='#updates' value='"+info.userId+"'>修改</button>"+
                                    "<button class='btn btn-danger btn-xs ' data-toggle='modal' value='"+info.userId+" 'id='delUsers'>删除</button></th></tr>";
                            });
                            $("#table-list").html(tr);
                            $("#prev").val(data.hasPreviousPage);
                            $("#next").val(data.hasNextPage);
                            $("#nowPage").val(data.pageNum);
                        }else {
                            alert("没有该电影类别");
                        }

                    }

                })

            });

            //删除
            $("#table-list").on("click", "#delUsers", function() {
                console.log($(this).val())
                $.ajax({
                    type:"get",
                    url:"${pageContext.request.contextPath }/admin/userDel",
                    data:{
                        userId:$(this).val(),
                    },
                    dataType:"json",
                    success:function(data){
                        if (data==1){
                            alert("删除成功")
                        }else {
                            alert("删除失败")
                        }
                        location.href="${pageContext.request.contextPath}/admin/lastUser";
                    }
                });

            });
                $("#table-list").on("click", "#updateUser", function() {
                $.ajax({
                    type:"get",
                    url:"${pageContext.request.contextPath }/admin/goUserUpdate",
                    data:{
                        userId:$(this).val()
                    },
                    dataType:"json",
                    success:function(data){
                        console.log(data);
                        $("#userId").val(data.userId);
                        $("#usersName").val(data.usersName);
                        $("#password").val(data.password);
                        $("#protrait").val(data.protrait);
                        $("#phone").val(data.phone);
                        $("#usersEmail").val(data.usersEmail);
                        $("#likeType").val(data.likeType);

                    }
                });

            });

            $("#doUsers").click(function () {
                console.log($("#userId").val());
                $.ajax({
                    type:"get",
                    url:"${pageContext.request.contextPath }/admin/doUserUpdate",
                    data:{
                        userId:$("#userId").val(),
                        usersName:$("#usersName").val(),
                        password:$("#password").val(),
                        protrait:$("#protrait").val(),
                        phone:$("#phone").val(),
                        usersEmail:$("#usersEmail").val(),
                        likeType:$("#likeType").val()

                    },
                    contentType:"application/json;charset=utf-8",//可有可无
                    dataType:"json",
                    success:function(data){
                        if (data!=null){
                            alert("修改成功");
                            window.location.href = "${pageContext.request.contextPath}/admin/lastUser";
                        }
                    }
                });
            });
        });
    </script>
</head>
<body>
<div role="tabpanel" class="tab-pane" id="chan">
    <div class="check-div form-inline">

        <div class="col-xs-4">
            <input type="text" class="form-control input-sm" placeholder="输入文字搜索" id="keyword">
            <button class="btn btn-white btn-xs " id="search">查 询 </button>
        </div>
    </div>
    <table class="table text-center" id="tab">
        <thead>
        <tr>
            <th>ID</th>
            <th>昵称</th>
            <th>密码</th>
            <th>头像</th>
            <th>手机号</th>
            <th>邮箱</th>
            <th>偏爱类型</th>
            <th colspan="2">操作</th>
        </tr>
        </thead>
        <tbody id="table-list">

        </tbody>





    </table>
</div>

<%--
<!-- 修改模态框（Modal） -->
<div class="modal fade" id="updates" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title" id="myModalLabel">
                    修改用户
                </h4>
            </div>
            <div class="modal-body">
                <input type="hidden" id="userId"/>
                昵称：<input type="text" id="usersName" /><br/>
                密码：<input type="text" id="password" /><br/>
                头像：<input type="text" id="protrait" /><br/>
                手机号：<input type="text" id="phone" /><br/>
                邮箱：<input type="text" id="usersEmail"><br/>
                偏爱类型：<input type="text" id="likeType">
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" data-dismiss="modal" id="doUsers">提交更改</button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal -->

--%>
<!--
               作者：offline
               时间：2019-12-24
               描述：修改用户模态框
           -->
<!--修改用户弹出窗口-->
<div class="modal fade" id="updates" role="dialog" aria-labelledby="gridSystemModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title" id="gridSystemModalLabel">修改用户信息</h4>
            </div>
            <div class="modal-body">
                <div class="container-fluid">
                    <form class="form-horizontal">
                        <input type="hidden" id="userId"/>
                        <div class="form-group ">
                            <label for="sName" class="col-xs-3 control-label">昵称：</label>
                            <div class="col-xs-6 ">
                                <input type="text" id="usersName"  class="form-control input-sm duiqi" id="sName" placeholder="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="sLink" class="col-xs-3 control-label">密码：</label>
                            <div class="col-xs-6 ">
                                <input type="text" id="password" class="form-control input-sm duiqi" id="sOrd" placeholder="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="sOrd" class="col-xs-3 control-label">头像：</label>
                            <div class="col-xs-6">
                                <input type="text" id="protrait" class="form-control input-sm duiqi" id="sOrd" placeholder="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="sLink" class="col-xs-3 control-label">手机号：</label>
                            <div class="col-xs-6 ">
                                <input type="text" id="phone"  class="form-control input-sm duiqi" id="sOrd" placeholder="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="sLink" class="col-xs-3 control-label">邮箱：</label>
                            <div class="col-xs-6 ">
                                <input type="text" id="usersEmail" class="form-control input-sm duiqi" id="sOrd" placeholder="">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="sLink" class="col-xs-3 control-label">偏爱类型：</label>
                            <div class="col-xs-6 ">
                                <input type="text" id="likeType" class="form-control input-sm duiqi" id="sOrd" placeholder="">
                            </div>
                        </div>
                    </form>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-xs btn-white" data-dismiss="modal">取 消</button>
                <button type="button" class="btn btn-xs btn-green" id="doUsers">保 存</button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>



</div>
<p style="text-align: center" id="p-button">
    <button class="btn btn-info" id="prev">上一页</button>
    <button class="btn btn-info" id="bt" value="1">第1页</button>
    <button class="btn btn-info" id="bt" value="2">第2页</button>
    <button class="btn btn-info" id="bt" value="3">第3页</button>
    <button class="btn btn-info" id="next">下一页</button>
</p>
<input type="hidden" id="nowPage"/>
</body>
</html>
